[PATCH] posix-cpu-timers: Cleanup CPU timers before freeing them during exec
authorThadeu Lima de Souza Cascardo <cascardo@canonical.com>
Fri, 22 Jul 2022 09:52:11 +0000 (06:52 -0300)
committerSalvatore Bonaccorso <carnil@debian.org>
Sat, 13 Aug 2022 13:25:10 +0000 (14:25 +0100)
commita7c11744ca7ca4161f4ad8cdce2986d3ae814e03
tree88d72a5dc4a0a24403aeafafe450eef1fc41aaed
parent57816a4ffa0c43efe15de27f41f05c67fe65ba97
[PATCH] posix-cpu-timers: Cleanup CPU timers before freeing them during exec

Commit 55e8c8eb2c7b ("posix-cpu-timers: Store a reference to a pid not a
task") started looking up tasks by PID when deleting a CPU timer.

When a non-leader thread calls execve, it will switch PIDs with the leader
process. Then, as it calls exit_itimers, posix_cpu_timer_del cannot find
the task because the timer still points out to the old PID.

That means that armed timers won't be disarmed, that is, they won't be
removed from the timerqueue_list. exit_itimers will still release their
memory, and when that list is later processed, it leads to a
use-after-free.

Clean up the timers from the de-threaded task before freeing them. This
prevents a reported use-after-free.

Fixes: 55e8c8eb2c7b ("posix-cpu-timers: Store a reference to a pid not a task")
Reported-by: "An independent security researcher working with SSD Secure Disclosure"
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
Gbp-Pq: Topic bugfix/all
Gbp-Pq: Name posix-cpu-timers-Cleanup-CPU-timers-before-freeing-t.patch
fs/exec.c